//
//  LJYVideoCollectionReusableView.m
//  WWLNetease
//
//  Created by 李锦耀 on 15/12/28.
//  Copyright © 2015年 Echo.Jobs. All rights reserved.
//

#import "LJYVideoCollectionReusableView.h"

@interface LJYVideoCollectionReusableView ()

@property(nonatomic, strong)UILabel *label;
@property(nonatomic, strong)UILabel *animaLabel;
@property(nonatomic, strong)UILabel *womanLabel;
@property(nonatomic, strong)UILabel *bestLabel;

@property(nonatomic, strong)UIButton *button;
@property(nonatomic, strong)UIButton *animaButton;
@property(nonatomic, strong)UIButton *womanButton;
@property(nonatomic, strong)UIButton *bestButton;

@property(nonatomic, strong)NSMutableArray *array;
@property(nonatomic, strong)UIImageView *backImageView;

@end

@implementation LJYVideoCollectionReusableView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        _array = [NSMutableArray array];
        
        _label = [[UILabel alloc] initWithFrame:CGRectMake(27, 60, 50, 25)];
        [self addSubview:_label];
        _label.backgroundColor = [UIColor yellowColor];
        _label.textAlignment = NSTextAlignmentCenter;
        _label.textColor = [UIColor redColor];
        _label.font = [UIFont systemFontOfSize:14.0];
        _label.text = @"草泥马";
        
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button.backgroundColor = [UIColor blueColor];
        _button.layer.masksToBounds = YES;
        _button.layer.cornerRadius = 20;
        [_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_button];
        [_button mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.equalTo(self.label).offset(7);
            make.width.height.mas_equalTo(40);
            make.bottom.equalTo(self.label.mas_top).offset(-8);
            
        }];
        
        _animaLabel = [[UILabel alloc] init];
        [self addSubview:_animaLabel];
        _animaLabel.backgroundColor = [UIColor yellowColor];
        _animaLabel.textAlignment = NSTextAlignmentCenter;
        _animaLabel.textColor = [UIColor redColor];
        _animaLabel.font = [UIFont systemFontOfSize:14.0];
        _animaLabel.text = @"草泥马";
        [_animaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
            make.left.equalTo(self.label.mas_right).offset(40);
            make.top.bottom.equalTo(self.label);
            make.width.height.equalTo(self.label);
        }];
        
        _animaButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _animaButton.backgroundColor = [UIColor blueColor];
        _animaButton.layer.masksToBounds = YES;
        _animaButton.layer.cornerRadius = 20;
        [_animaButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_animaButton];
        [_animaButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            
            make.width.height.mas_equalTo(40);
            make.left.equalTo(self.animaLabel).offset(7);
            make.center.equalTo(self.animaLabel.mas_centerY);
            make.bottom.equalTo(self.animaLabel.mas_top).offset(-8);
            
        }];
        
        _womanLabel = [[UILabel alloc] init];
        [self addSubview:_womanLabel];
        _womanLabel.backgroundColor = [UIColor yellowColor];
        _womanLabel.textAlignment = NSTextAlignmentCenter;
        _womanLabel.textColor = [UIColor redColor];
        _womanLabel.font = [UIFont systemFontOfSize:14.0];
        _womanLabel.text = @"草泥马";
        [_womanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.animaLabel.mas_right).offset(40);
            make.top.bottom.equalTo(self.label);
            make.width.height.equalTo(self.label);
            
        }];
        
        _womanButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _womanButton.backgroundColor = [UIColor blueColor];
        _womanButton.layer.masksToBounds = YES;
        _womanButton.layer.cornerRadius = 20;
        [_womanButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_womanButton];
        [_womanButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.height.mas_equalTo(40);
            make.left.equalTo(self.womanLabel).offset(7);
            make.center.equalTo(self.womanLabel.mas_centerY);
            make.bottom.equalTo(self.womanLabel.mas_top).offset(-8);
            
        }];
        
        _bestLabel = [[UILabel alloc] init];
        [self addSubview:_bestLabel];
        _bestLabel.backgroundColor = [UIColor yellowColor];
        _bestLabel.textAlignment = NSTextAlignmentCenter;
        _bestLabel.textColor = [UIColor redColor];
        _bestLabel.font = [UIFont systemFontOfSize:14.0];
        _bestLabel.text = @"草泥马";
        [_bestLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            
            make.left.equalTo(self.womanLabel.mas_right).offset(40);
            make.top.bottom.equalTo(self.label);
            make.width.height.equalTo(self.label);
            
        }];
        
        _bestButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _bestButton.backgroundColor = [UIColor blueColor];
        _bestButton.layer.masksToBounds = YES;
        _bestButton.layer.cornerRadius = 20;
        [_bestButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_bestButton];
        [_bestButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.width.height.mas_equalTo(40);
            make.left.equalTo(self.bestLabel).offset(7);
            make.center.equalTo(self.bestLabel.mas_centerY);
            make.bottom.equalTo(self.bestLabel.mas_top).offset(-8);
            
        }];
    }
    return self;
}

-(void)setTopButtonArray:(NSMutableArray *)topButtonArray
{
    for (NSDictionary *dic in topButtonArray)
    {
        _topButton = [[LJYVideoTopButtonModel alloc] init];
        [_topButton setValuesForKeysWithDictionary:dic];
        [self.array addObject:self.topButton];
        UIImageView *image = [[UIImageView alloc] init];
        if ([_topButton.title isEqualToString:@"奇葩"])
        {
            [image sd_setImageWithURL:[NSURL URLWithString:self.topButton.imgsrc] placeholderImage:[UIImage imageNamed:@"u=1625671141,2113623839&fm=21&gp=0.jpg"]];
            [self.button setImage:image.image forState:UIControlStateNormal];
            self.button.tag = 1001;
            self.label.text = self.topButton.title;
        }
        else if ([_topButton.title isEqualToString:@"萌物"])
        {
            [image sd_setImageWithURL:[NSURL URLWithString:self.topButton.imgsrc] placeholderImage:[UIImage imageNamed:@"u=1625671141,2113623839&fm=21&gp=0.jpg"]];
            [self.animaButton setImage:image.image forState:UIControlStateNormal];
            self.animaButton.tag = 1002;
            self.animaLabel.text = self.topButton.title;
        }
        else if ([_topButton.title isEqualToString:@"美女"])
        {
            [image sd_setImageWithURL:[NSURL URLWithString:self.topButton.imgsrc] placeholderImage:[UIImage imageNamed:@"u=1625671141,2113623839&fm=21&gp=0.jpg"]];
            [self.womanButton setImage:image.image forState:UIControlStateNormal];
            self.womanButton.tag = 1003;
            self.womanLabel.text = self.topButton.title;
        }
        else if ([_topButton.title isEqualToString:@"精品"])
        {
            [image sd_setImageWithURL:[NSURL URLWithString:self.topButton.imgsrc] placeholderImage:[UIImage imageNamed:@"u=1625671141,2113623839&fm=21&gp=0.jpg"]];
            [self.bestButton setImage:image.image forState:UIControlStateNormal];
            self.bestButton.tag = 1004;
            self.bestLabel.text = self.topButton.title;
        }
       
    }

}
-(void)buttonAction:(UIButton *)btn
{
    if (btn.tag == 1001)
    {
        [self.delegate gotoOtherTypeVideoMethodWithModel:[self.array objectAtIndex:btn.tag%1000-1]];
         NSLog(@"11111%@",[self.array objectAtIndex:btn.tag%1000]);
    }
    else if (btn.tag == 1002)
    {
        [self.delegate gotoOtherTypeVideoMethodWithModel:[self.array objectAtIndex:btn.tag%1000-1]];
        NSLog(@"22222%@",[self.array objectAtIndex:btn.tag%1000]);
    }
    else if (btn.tag == 1003)
    {
        [self.delegate gotoOtherTypeVideoMethodWithModel:[self.array objectAtIndex:btn.tag%1000-1]];
        NSLog(@"333333%@",[self.array objectAtIndex:btn.tag%1000]);
    }
    else if (btn.tag == 1004)
    {
        [self.delegate gotoOtherTypeVideoMethodWithModel:[self.array objectAtIndex:btn.tag%1000-1]];
        NSLog(@"444444%@",[self.array objectAtIndex:btn.tag%1000]);
    }
    
}

@end
